from starlette.endpoints import HTTPEndpoint
from starlette.responses import JSONResponse
from model.ModProblemTypeList import ProblemTypeList,problemTypeListSchema
from database import Session, engine
import datetime


def get_problem_info(session):
    #根据终端类型查询问题信息
        problem_info = session.query(ProblemTypeList).order_by(ProblemTypeList.proid.asc()).all()
        return JSONResponse(problemTypeListSchema.dump(problem_info, many=True).data)

def insert_pro(session, pro):
    # 新增问题类型
    try:
        session.add(pro)
    except Exception as e:
        raise

def get_problem_max(session):
    #查询问题最大id值
        problem_info = session.query(ProblemTypeList).filter(ProblemTypeList.proid != '99').all()
        list_pro = problemTypeListSchema.dump(problem_info, many=True).data
       # max_info = max(list_pro,key=lambda item: item["proid"]) 返回最大值所在元素的整个元素
        max_info = 0
        if len(list_pro) > 0:
            max_info = max([item["proid"] for item in list_pro])
        return max_info
